package com.hopu.v1.service.admin.classes.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.v1.exception.BusinessException;
import com.hopu.v1.pojo.classes.ClassCourseProgress;
import com.hopu.v1.service.admin.classes.ClassCourseProgressService;
import com.hopu.v1.mapper.admin.classes.ClassCourseProgressMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author DELL
* @description 针对表【t_class_course_progress(班级课程进度表)】的数据库操作Service实现
* @createDate 2024-09-25 16:25:45
*/
@Service
public class ClassCourseProgressServiceImpl extends ServiceImpl<ClassCourseProgressMapper, ClassCourseProgress>
    implements ClassCourseProgressService{

    @Resource
    private ClassCourseProgressMapper classCourseProgressMapper;

    @Override
    public List<ClassCourseProgress> ClassCourseList() {
        return classCourseProgressMapper.ClassCourseList();
    }

    @Override
    public void insertClassCourseProgress(ClassCourseProgress classCourseProgress) {
        LambdaQueryWrapper<ClassCourseProgress> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ClassCourseProgress::getClassId, classCourseProgress.getClassId());
        wrapper.eq(ClassCourseProgress::getCourseId, classCourseProgress.getCourseId());
        int count = Math.toIntExact(classCourseProgressMapper.selectCount(wrapper));
        if (count > 0) {
            throw new BusinessException("该班级已结束此课程！不能重复操作");
        }
        save(classCourseProgress);
    }


}




